<?php

#--------------------------------------------------
# ALL INCLUDES + STANDARD-VALUES
#--------------------------------------------------
include_once ("include/config.inc");
include_once ("include/template.inc");
include_once ("include/class.db.php5");
include_once ("include/class.tools.php5");
$svo = new db("svoptik");
$tools = new tool();

include_once ("include/global_fix_extern.inc");

#--------------------------------------------------
# CREATE TEMPLATE
#--------------------------------------------------
$t = new Template("templates", "keep");
$t->set_file(array (
	"page" => "svoptik_popup.tpl",
	"member" => "new_member.tpl"
));
#--------------------------------------------------

$t->set_var(array (
	"FORWARD" => ""
));
#--------------------------------------------------
# CREATE CONTENT "NEW MEMBER"
#--------------------------------------------------
global $member_vname, $member_name, $member_password, $member_conf_pass, $member_nick, $member_email, $send;

$t->set_var(array (
	"VORNAME" => $member_vname,
	"NAME" => $member_name,
	"USERNAME" => $member_nick,
	"EMAIL" => $member_email,
	"MSG" => ""
));

if (!$send)
	$content = $t->parse("", "member", true);
else {
	$content = "
	      <script language=\"javascript\">
	      <!--
	      function win_close() {
	          opener.location.replace('login.php5');
	          window.close();
	      }
	      //-->
	      </script>
	      ";
	$user_names = $svo->doSQL("select usr_nick from " . $table['User'] . ";");
	while ($row = mysql_fetch_array($user_names)) {
		if ($row['usr_nick'] == $member_nick) {
			$user_nick_check = 1;
			$user_nick_msg = "<br>Username schon vorhanden!";
			break;
		} else {
			$user_nick_check = 0;
			$user_nick_msg = "";
		}
	}

	if ($user_nick_check || empty ($member_name) || empty ($member_vname) || empty ($member_nick) || empty ($member_password) || empty ($member_conf_pass) || $member_password != $member_conf_pass || empty ($member_email) || !ereg("^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})", $member_email)) {
		$t->set_var(array (
			"MSG" => "Bitte &uuml;berpr&uuml;fen Sie Ihre Eingaben!" . $user_nick_msg
		));
		$content .= $t->parse("", "member", true);
	} else {
		if ($svo->doSQL("insert into " . $table['User'] . " (usr_name, usr_vname, usr_email, usr_nick, usr_passwd) values ('" . $member_name . "', '" . $member_vname . "', '" . $member_email . "', '" . $member_nick . "', '" . $member_password . "');"))
			$content .= "<p align=\"center\" class=\"text\"><br><br><br>Die Member-Area steht Dir jetzt offen.<br>Beim Login einfach deinen Usernamen und dein Passwort eingeben, und schon geht's los.<br><br><a href=\"javascript:win_close();\" class=\"text\">Fenster schlie&szlig;en</a></p>";
		else
			$content .= "<p align=\"center\" class=\"text\"><br><br><br>Leider konnte deine Anfrage nicht von der Datenbank entgegengenommen werden. Bitte versuche es zu einem sp&auml;teren Zeitpunkt erneut. Sollten diese Probleme weiterhin bestehen wende dich bitte an den Administrator. Unter dem Men&uuml;-Punkt &quot;kontakt&quot; -> &quot;mail @ sv optik&quot; findest du ein Kontaktformular.<br><br><a href=\"javascript:win_close();\" class=\"text\">Fenster schlie&szlig;en</a></p>";

		$mail_subject = "Eintragung neues Mitglied SV Optik " . $member_name . ", " . $member_vname . " [" . $member_email . "]";
		$mail_name = "Administrator";
		$mail_to = "webmaster@sv-optik.de";

		$mail_text = "neuer user hat sich eingetragen " . date("H:i:s d.m.Y");

		$header = "From:" . $member_name . ", " . $member_vname . " <" . $member_email . ">\n";
		$header .= "Reply-To: " . $member_email . "\n";
		$header .= "X-Mailer: PHP/" . phpversion() . "\n";
		$header .= "X-Sender-IP: " . $REMOTE_ADDR . "\n";
		$header .= "Content-Type: text/plain";

		@ mail($mail_to, $mail_subject, $mail_text, $header);
	}
}

#--------------------------------------------------

#--------------------------------------------------
# PARSE & OUTPUT
#--------------------------------------------------
$t->set_var(array (
	"NAVI" => "<img src=\"standard/spacer.gif\" width=\"10\" height=\"20\" border=\"0\" alt=\"\">",
	"sitenav" => "MEMBERAREA -> ANMELDEN",
	"content" => $content
));

$t->parse("ALL", "page", true);
$t->p("ALL");
?>
